package jgdabc.controller;


import jgdabc.config.PoetryResult;
import jgdabc.entity.Resource;
import jgdabc.service.ResourceService;
import jgdabc.utils.QiniuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/resource")
public class ResourceController {
    @Value("${qiniu.downloadUrl}")
    private String downloadUrl;

    @Autowired
    private ResourceService resourceService;

    @Autowired
    private QiniuUtil qiniuUtil;

    @PostMapping("/saveResource")
    public PoetryResult saveResource(@RequestBody Resource resource) {
        if (!StringUtils.hasText(resource.getType()) || !StringUtils.hasText(resource.getPath())) {
            return PoetryResult.fail("资源类型和资源路径不能为空！");
        }
        Resource re = new Resource();


//
//        if (resource.getType().equalsIgnoreCase("video")){
//            resourceVideo.setPath(resource.getPath());
//            resourceVideo.setType(resource.getType());
//            resourceVideo.setSize(resource.getSize());
//            resourceVideo.setMimeType(resource.getMimeType());
//            resourceVideo.setUserId(PoetryUtil.getUserId());
//            resourceVideoService.save(resourceVideo);

//        }else {
        re.setPath(resource.getPath());
        re.setType(resource.getType());
        re.setSize(resource.getSize());
        re.setMimeType(resource.getMimeType());
        re.setUserId(0);

        resourceService.save(re);
//        }


        return PoetryResult.success();
    }

}
